package com.zzyl.controller.customer;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ReservationQueryDto;
import com.zzyl.entity.Reservation;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.TimeCountVo;
import com.zzyl.vo.VisitVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController {

    @Autowired
    ReservationService reservationService;

    //TODO @ApiOperation("查询取消预约数量")
    @GetMapping("cancelled-count")
    public ResponseResult<Integer> cancelled() {
        Integer count = reservationService.cancelledcount();
        return ResponseResult.success(count);
    }

    //TODO @ApiOperation("查询每个时间段剩余预约次数")
    @GetMapping("/countByTime")
    public ResponseResult<List<TimeCountVo>> countByTime(Long time) {
        List<TimeCountVo> vo = reservationService.countByTime(time);
        return ResponseResult.success(vo);
    }

    //TODO @ApiOperation("新增预约")
    @PostMapping
    public ResponseResult<Void> add(@RequestBody Reservation reservation) {
        reservationService.add(reservation);
        return ResponseResult.success();
    }
    //TODO @ApiOperation("分页查询预约")
    @GetMapping("/page")
    public ResponseResult<PageBean<VisitVo>> query(ReservationQueryDto dto){
       PageBean<VisitVo> visitVos= reservationService.query(dto);
    return ResponseResult.success(visitVos);
    }

    //TODO @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public ResponseResult<Void> cancel(@PathVariable Long id){
        reservationService.cancel(id);
        return ResponseResult.success();
    }

}
